<template>
    <div class="complete-container">
        <div v-if="status">
            <img src="../assets/success.png" />
            <div class="complete-status">支付成功</div>
        </div>
        <div v-else>
            <img src="../assets/failed.png" />
            <div class="complete-status">支付失败</div>
        </div>
        <div class="back-to-index" @click="backIndex"><span>返回首页</span></div>
    </div>
</template>
<script>
export default {
    data(){
        return{
            status:false
        }
    },
    created(){
        let that = this
        that._load()
    },
    methods:{
        _load(){
            let that = this
            that.$api.ajax([that.queryResult()])
        },
        backIndex(){
            this.$router.push("Index")
        },
        queryResult(){
            let that = this;
            let params = {
                tradeNo:that.$storage.get("tradeNo"),
                openid:that.$storage.get("openid")
            }
            return new Promise(function (resolve,reject) {
                that.$api.getOrder(params).then(res => {
                    console.log(res)
                    if(res.paymentState==='PAID'){
                        that.status = true
                    }
                    resolve()  
                }).catch(err=>{
                    resolve() 
                })
            });
        }
    }
}
</script>
<style lang="less" scoped>
.complete-container{
    width: 100%;
    height: 100vh;
    background-color:#f5f5f5;
    font-size: 4vw;
    text-align: center;
    font-family: "微软雅黑";
    img{
        width: 22%;
        display: block;
        margin: 0 auto;
        padding-top: 28%;
    }
    .complete-status{
        margin-top: 3.7%;
    }
    .back-to-index{
        width: 94%;
        margin: 0 auto;
        margin-top: 19%;
        border: 1px solid #fab17f;
        border-radius: 2vw;
        padding: 3.1% 0 3% 0;
        color: #fe6d0a;
    }
}
</style>
